home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0104_Cannon Ball Animation.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  2KB  |  107 lines

  1. {
  2.  JG> This coding works fine, I would like to make the ball travel
  3.  JG> smoother.  When it travels in the air, its kinda "Chunky"
  4.  
  5.  JG> How could you make it so that the computer calculates the next
  6.  JG> point and make it travel the ball to that point one pixel at a
  7.  JG> time?  Cause with this structure, it kinda "Jumps there"
  8.  
  9.         Try next code and tell me ...
  10. }
  11.  
  12. Program FallingBall;
  13.  
  14. { Written by Luis Mezquita Raya }
  15.  
  16. {$x+}
  17.  
  18. uses  Crt,
  19.       Graph;
  20.  
  21. Procedure Init;
  22. var cg,mg:integer;
  23. begin
  24.  cg:=Detect;
  25.  InitGraph(cg,mg,'\turbo\tp');
  26. end;
  27.  
  28. Procedure Wait(msk:byte); assembler;
  29. asm
  30.         mov dx,3dah
  31. @Loop1: in al,dx
  32.         test al,msk
  33.         jz @Loop1
  34. @Loop2: in al,dx
  35.         test al,msk
  36.         jnz @Loop2
  37. end;
  38.  
  39. Procedure Calc;
  40. var angle,power,gravity,a1,a2,a3,y0,n:real;
  41.     size:word;
  42.     ball,mask,bkg:pointer;
  43.     x,y,ox,oy,pause:integer;
  44. begin
  45.  
  46.  ClearViewPort;
  47.  
  48.  size:=ImageSize(0,0,20,20);
  49.  GetMem(ball,size);
  50.  GetMem(mask,size);
  51.  GetMem(bkg,size);
  52.  
  53.  SetFillStyle(SolidFill,Yellow);        { Draw a ball }
  54.  Circle(10,10,8);
  55.  FloodFill(10,10,White);
  56.  GetImage(0,0,20,20,ball^);             { Get the ball }
  57.  
  58.  SetFillStyle(SolidFill,White);         { Draw ball's mask }
  59.  Bar(0,0,20,20);
  60.  SetFillStyle(SolidFill,Black);
  61.  SetColor(Black);
  62.  Circle(10,10,10);
  63.  FloodFill(10,10,Black);
  64.  GetImage(0,0,20,20,mask^);             { Get the mask }
  65.  
  66.  ClearViewPort;                         { Draw a background }
  67.  SetFillStyle(CloseDotFill,LightBlue);
  68.  Bar(0,0,GetMaxX,GetMaxY);
  69.  
  70.  angle:=35;                             { Init vars }
  71.  power:=10;
  72.  gravity:=0.1;
  73.  y0:=200;
  74.  ox:=-1;
  75.  n:=0;
  76.  
  77.  while n<80 do                          { Main loop }
  78.   begin
  79.    a1:=cos(angle*pi/180)*power*n;
  80.    a2:=y0-sin(angle*pi/180)*power*n;
  81.    a3:=gravity*n*n;
  82.    x:=Round(a1);
  83.    y:=Round(a2+a3);
  84.    Wait(8);                             { Wait retrace }
  85.    for pause:=0 to 399 do Wait(1);      { Wait scan line }
  86.    if ox<>-1                            { Restore old background }
  87.    then PutImage(ox,oy,bkg^,CopyPut);
  88.    GetImage(x,y,x+20,y+20,bkg^);        { Save background }
  89.    PutImage(x,y,mask^,AndPut);          { Put mask }
  90.    PutImage(x,y,ball^,OrPut);           { Put ball }
  91.    ox:=x;
  92.    oy:=y;
  93.    n:=n+0.2;
  94.   end;
  95.  
  96.  FreeMem(ball,size);
  97.  FreeMem(mask,size);
  98. end;
  99.  
  100.  
  101. begin
  102.  Init;
  103.  Calc;
  104.  ReadKey;
  105.  CloseGraph;
  106. end.
  107.